﻿@model ProductOverviewModel

@{
    var parentModel = ViewData["Parent"] as ProductListModel;
}

<datagrid id="products-grid"
          version="3"
          allow-resize="true"
          allow-row-selection="true"
          allow-edit="true"
          preserve-grid-state="true" preserve-command-state="true"
          allow-column-reordering="true">
    <datasource read="@Url.Action("ProductList")" delete="@Url.Action("ProductDelete")" update="@Url.Action("ProductUpdate")" />
    <paging position="Bottom" page-index="1" show-size-chooser="true" />
    <sorting allow-unsort="true" allow-multisort="false"></sorting>
    <toolbar>
        <toolbar-group>
            <button datagrid-action="DataGridToolAction.ToggleSearchPanel" type="button" class="btn btn-light btn-icon">
                <i class="fa fa-fw fa-filter"></i>
            </button>
        </toolbar-group>
        <toolbar-group>
            <a asp-action="Create" class="btn btn-primary btn-flat no-anims mr-auto">
                <i class="fa fa-plus"></i>
                <span>@T("Admin.Common.AddNew")...</span>
            </a>
            <button datagrid-action="DataGridToolAction.SaveChanges" type="button" class="btn btn-warning no-anims btn-flat">
                <i class="fa fa-check"></i>
                <span>@T("Admin.Common.SaveChanges")</span>
            </button>
            <button datagrid-action="DataGridToolAction.CancelEdit" type="button" class="btn btn-light btn-flat mr-auto">
                <span>@T("Common.Cancel")</span>
            </button>
        </toolbar-group>
        <zone name="datagrid_toolbar_alpha"></zone>
        <toolbar-group class="omega"></toolbar-group>
        <zone name="datagrid_toolbar_omega"></zone>
        <toolbar-group>
            <button datagrid-action="DataGridToolAction.DeleteSelectedRows" type="button" class="btn btn-danger no-anims btn-flat">
                <i class="far fa-trash-can"></i>
                <span>@T("Admin.Common.Delete.Selected")</span>
            </button>
        </toolbar-group>
    </toolbar>
    <search-panel>
        <partial name="Grids/_Grid.Products.Search" model="parentModel" />
    </search-panel>
    <columns>
        @if (parentModel.DisplayProductPictures)
        {
            <column for="PictureThumbnailUrl"
                    title=""
                    width="48px"
                    sortable="false"
                    visible="true"
                    readonly="true"
                    resizable="false"
                    reorderable="false">
                <display-template>
                    <div v-if="item.row.Id > 0" class="hstack justify-content-center position-absolute w-100 h-100 top-0 start-0" style="padding: 8px;">
                        <img :alt="item.row.Id" :src="item.value" style="max-width: 42px; max-height: 32px" />
                    </div>
                </display-template>
            </column>
        }
        <column for="Name" width="3fr" hideable="false">
            <display-template>
                @Html.LabeledProductName()
            </display-template>
        </column>
        <column for="Sku" />
        <column for="Gtin" visible="false" />
        <column for="ManufacturerPartNumber" visible="false" />
        <column for="Price" halign="flex-end" />
        <column for="ComparePrice" halign="flex-end" visible="false" />
        <column for="DeliveryTimeId" halign="center" width="200px">
            <display-template>
                <div class="dg-cell-value">{{ item.row.DeliveryTime }}</div>
            </display-template>
        </column>
        <column for="StockQuantity" halign="center" />
        <column for="MinStockQuantity" halign="center" visible="false" />
        <column for="LimitedToStores" visible="!parentModel.IsSingleStoreMode" readonly="true" halign="center" />
        <column for="CreatedOn" entity-member="CreatedOnUtc" readonly="true" visible="false" />
        <column for="UpdatedOn" entity-member="UpdatedOnUtc" readonly="true" />
        <column for="Published" halign="center" />
        <column for="DisplayOrder" halign="center" visible="false" />
        <column for="AvailableStartDateTimeUtc" visible="false" />
        <column for="AvailableEndDateTimeUtc" visible="false" />
    </columns>
    <row-commands>
        <a datarow-action="DataRowAction.Custom" :href="item.row.EditUrl">@T("Common.Edit")</a>
        <a datarow-action="DataRowAction.Custom"
           class="copy-product-command"
           href="#copyproduct-window"
           data-toggle="modal"
           :data-copy-product-id="item.row.Id"
           :data-copy-product-name="item.row.CopyProductModel.Name">
            @T("Common.Copy")
        </a>
        <div class="dropdown-divider"></div>
        <a datarow-action="DataRowAction.Delete">@T("Common.Delete")</a>
    </row-commands>
</datagrid>

<partial name="_CopyProductDialog" model="null" />

<script sm-target-zone="scripts" data-origin="products-grid">
    $(function () {
        window.Res.DataGrid.confirmDelete = @T("Admin.DataGrid.ConfirmSoftDelete").JsValue;
        window.Res.DataGrid.confirmDeleteMany = @T("Admin.DataGrid.ConfirmSoftDeleteMany").JsValue;        
    });
</script>